<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form :labelCol="labelCol" :wrapperCol="wrapperCol" ref="queryForm">
          <a-row :gutter="32">
            <a-col :span="5" style="">
              <a-form-item label="考核标题">
                <a-input
                  v-model="queryParam.assessTitle"
                  placeholder="请输入部门名称"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="5">
              <a-form-item label="部门名称">
                <a-input
                  v-model="queryParam.deptName"
                  placeholder="请输入部门名称"
                  allow-clear
                  @keyup.enter.native="handleQuery"
                />
              </a-form-item>
            </a-col>
            <a-col :span="5">
              <a-form-item label="截止时间">
                <a-range-picker
                  style="width: 100%"
                  v-model="dateRangeEndTime"
                  valueFormat="YYYY-MM-DD"
                  format="YYYY-MM-DD"
                  allow-clear
                />
              </a-form-item>
            </a-col>
            <a-col :span="5">
              <a-form-item label="发布时间">
                <a-range-picker
                  style="width: 100%"
                  v-model="dateRangeFabuTime"
                  valueFormat="YYYY-MM-DD"
                  format="YYYY-MM-DD"
                  allow-clear
                />
              </a-form-item>
            </a-col>
            <a-col>
              <span
                class="table-page-search-submitButtons"
                style="float: right"
              >
                <a-button type="primary" @click="handleQuery"
                  ><a-icon type="search" />查询</a-button
                >
                <a-button style="margin-left: 8px" @click="resetQuery"
                  ><a-icon type="redo" />重置</a-button
                >
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false" class="table-card">
      <!-- 增加 -->

      <!-- 编辑 -->
      <biz-assess-to-dept-details-ping-fen-form
        v-if="showEditModal"
        ref="bizAssessToDeptDetailsPingFenForm"
        @ok="getList"
        @close="showEditModal = false"
      />
      <advance-table
        title="考核部门"
        :pagination="{
          current: queryParam.pageNum,
          pageSize: queryParam.pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          showTotal: (total, range) =>
            `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
          onChange: changeSize,
          onShowSizeChange: onShowSizeChange,
        }"
        tableKey="base-bizAssessToDept-index-table"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="bizAssessToDeptList"
        :loading="loading"
        :format-conditions="true"
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
      >
        <span slot="operation" slot-scope="{ text, record }">
          <a v-if="record.status == '1'"> <a-icon type="stop" /> 待提交资料 </a>
          <a @click="handleUpdate(record)" v-else-if="record.status == '2'">
            <a-icon type="form" /> 考核评分
          </a>
          <a @click="handleUpdate(record)" v-else-if="record.status == '3'">
            <a-icon type="search" /> 查看详情
          </a>
        </span>
        <span slot="rowindex" slot-scope="{ index }">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="{ record }">
          <a-tag v-if="record.status == 1" color="#108ee9">待提交资料</a-tag>
          <a-tag v-else-if="record.status == 2" color="#2db7f5">
            已审核,待评分</a-tag
          >
          <a-tag v-else-if="record.status == 3" color="#87d068">考核完成</a-tag>
        </span>
        <span slot="assessScore" slot-scope="{ text, record }">
          <span style="color: #f50" v-if="record.status == 3">{{ text }}</span>
          <span v-else>待评分</span>
        </span>
      </advance-table>
    </a-card>
  </div>
</template>
<script>
import {
  assessDetplist,
  exportBizAssessToDept,
} from "@/api/biz/bizAssessToDept";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import BizAssessToDeptDetailsPingFenForm from "@/views/biz/bizassesstodept/modules/BizAssessToDeptDetailsPingFenForm.vue";
export default {
  name: "BizAssessToDept",
  components: {
    AdvanceTable,
    BizAssessToDeptDetailsPingFenForm,
  },
  data() {
    return {
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 考核部门表格数据
      bizAssessToDeptList: [],
      dateRangeEndTime: [],
      dateRangeFabuTime: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        assessTitle: undefined,

        beginEndTime: undefined,
        status: 2,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "3%",
          scopedSlots: { customRender: "rowindex" },
        },
        {
          title: "考核标题",
          dataIndex: "assessTitle",
          ellipsis: true,
          align: "center",
        },
        {
          title: "部门名称",
          dataIndex: "deptName",
          ellipsis: true,
          align: "center",
          width: "12%",
        },
        {
          title: "发布时间",
          dataIndex: "fabuTime",
          align: "center",
          width: "10%",
        },
        {
          title: "截止时间",
          dataIndex: "endTime",
          align: "center",
          width: "10%",
        },

        {
          title: "考核得分",
          dataIndex: "assessScore",
          align: "right",
          width: "7%",
          scopedSlots: { customRender: "assessScore" },
        },
        {
          title: "状态",
          dataIndex: "status",
          align: "center",
          width: "13%",
          scopedSlots: { customRender: "status" },
        },
        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "10%",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询考核部门列表 */
    getList() {
      this.loading = true;
      if (this.dateRangeEndTime !== null && this.dateRangeEndTime !== "") {
        this.queryParam.beginEndTime = this.dateRangeEndTime[0];
        this.queryParam.endEndTime = this.dateRangeEndTime[1];
      }
      if (this.dateRangeFabuTime !== null && this.dateRangeFabuTime !== "") {
        this.queryParam.beginFabuTime = this.dateRangeFabuTime[0];
        this.queryParam.endFabuTime = this.dateRangeFabuTime[1];
      }
      assessDetplist(this.queryParam).then((response) => {
        this.bizAssessToDeptList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        assessTitle: undefined,

        beginEndTime: undefined,
        status: 2,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() => this.$refs.bizAssessToDeptAddForm.handleAdd());
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizAssessToDeptDetailsPingFenForm.handlePingFenUpdate(
          record,
          ids
        )
      );
    },
    /** 删除按钮操作 */

    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizAssessToDept(that.queryParam).then((response) => {
            that.download(response.msg);
            that.$message.success("导出成功", 3);
          });
        },
        onCancel() {},
      });
    },
  },
};
</script>
